<?php

class Application_Form_Inversiones extends Sgit_Form
{

    public function init_form()
    {
        $request = Zend_Controller_Front::getInstance()->getRequest();
        $id = $request->getParam('id');


        $peticion =     Sgit_Util_FileUpload::run('inversion','peticion');
        $aprobacion =   Sgit_Util_FileUpload::run('inversion','aprobacion');
        $noc =          Sgit_Util_FileUpload::run('inversion','noc');




        $ubicacion = new Sgit_Form_Element_Select_Year('anio');
        $ubicacion->setRequired();
        $this->addElement($ubicacion);

        $element = new Sgit_Form_Element_Select_Mes('mes');
        $element->setRequired();
        $this->addElement($element);

 

        $files_0=new Zend_Form_Element_File($peticion['name']);
       
        $files_0->setLabel('Petición Inversión')
                ->setDestination($peticion['dir'])
                ->addValidator('Size', false, 31457280)
                ->setValueDisabled(true);
        $this->addElement($files_0);


        if($id){
             $options=Sgit_Util_GetFiles::run($peticion['tabla'],$peticion['key'],$id);
             
             if($options){
                 $files_lista0 = new Zend_Form_Element_MultiCheckbox($peticion['activo']);
                 $files_lista0->setMultiOptions($options)
                    ->setLabel('Borrar Petición Inversión')
                    ->setAttrib('size',25); 
                 $this->addElement($files_lista0);
             }
         }
         
         
         $files_1=new Zend_Form_Element_File($aprobacion['name']);
         $files_1->setLabel('Aprobación Inversión')
                ->setDestination($aprobacion['dir'])
                ->addValidator('Size', false, 31457280)
                ->setValueDisabled(true);
         $this->addElement($files_1);


        if($id){
             $options=Sgit_Util_GetFiles::run($aprobacion['tabla'],$aprobacion['key'],$id);
             
             if($options){
                 $files_lista1 = new Zend_Form_Element_MultiCheckbox($aprobacion['activo']);
                 $files_lista1->setMultiOptions($options)
                    ->setLabel('Borrar Aprobación Inversión')
                    ->setAttrib('size',25); 
                 $this->addElement($files_lista1);
             }
         }
         
         
         $files_2=new Zend_Form_Element_File($noc['name']);
         $files_2->setLabel('NOC')
                ->setDestination($noc['dir'])
                ->addValidator('Size', false, 31457280)
                ->setValueDisabled(true);
         $this->addElement($files_2);


        if($id){
             $options=Sgit_Util_GetFiles::run($noc['tabla'],$noc['key'],$id);
             
             if($options){
                 $files_lista2 = new Zend_Form_Element_MultiCheckbox($noc['activo']);
                 $files_lista2->setMultiOptions($options)
                    ->setLabel('Borrar NOC')
                    ->setAttrib('size',25); 
                 $this->addElement($files_lista2);
             }
         }  
         
         


        $notas = new Zend_Form_Element_Textarea('notas');
        $notas->setLabel('Notas')->setAttribs(array('rows' => 3, 'cols' => 60));
        $this->addElement($notas);


        $this->setElementDecorators($this->getDecoratorElement());

        //fix file 
        $files_2->setDecorators($this->getDecoratorFile());
        $files_1->setDecorators($this->getDecoratorFile());
        $files_0->setDecorators($this->getDecoratorFile());

    }
}
